import Vue from 'vue'
import dayjs from 'dayjs'
import 'dayjs/locale/zh-cn'
import relativeTime from 'dayjs/plugin/relativeTime'

dayjs.locale('zh-cn')
dayjs.extend(relativeTime)

Vue.filter('filterTime', (timeStamp, format = 'HH:mm A') => {
  if (!timeStamp) return ''
  return dayjs(timeStamp).format(format)
})

// 全局过滤器：处理相对时间
Vue.filter('relativeTime', (value) => {
  return dayjs().to(dayjs(value).add(1, 'day'))
})

Vue.filter('filterType', (value) => {
  switch (value) {
    case 1:
      return '法定工作日'
    case 2:
      return '只想一次'
    case 3:
      return '每天'
  }
})
